package rack.lite.view

import rack.lite.view.AlunoView
import rack.lite.view.DisciplinaView
import rack.lite.view.AlunoDisciplinaView

/**
 *
 * @author atila
 */
@Singleton class Console {

   def static final String bash = "rack-lite:\$ > "
   def static final String info = "[i]"
   def static final String warning = "[!]"
   def static final Scanner read = new Scanner(System.in).useDelimiter("\n")

   def view() {
      def option
      while (true) {
         menu()
         print bash
         option = read.nextLine()
         switch (option) {
            case "A":
               AlunoView.instance.index()
               continue
            case "D":
               DisciplinaView.instance.index()
               continue
            case "rAD":
               AlunoDisciplinaView.instance.index()
               continue
            case ["/sair", "/quit", "/exit"]:
               clearConsole()
               return false
            case "/clear":
               clearConsole()
            default:
               println "Opção inválida."
               continue
         }
      }
   }

   def menu() {
      clearConsole()
      def builder = new StringBuilder()
      builder.append(" \u03C6 Rackademico Lite - powered by Groovy \u03C6 ".center(60, "·"))
      builder.append("\n")
      builder.append(" Menu Principal ".center(50, "·"))
      builder.append("\n\n")
      builder.append("[A]lunos\n")
      builder.append("[D]isciplinas\n")
      builder.append("[rAD]Aluno_Disciplina\n")
      builder.append("[/sair][/quit][/exit][/clear]")
      println builder.toString()
   }

   static void clearConsole() {
      //Thread.sleep(1000)
      /* testar SO para Linux ou Windows */
      System.out.printf("\033c")
   }
}

